using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using GonzalesCore.CoreElements;
using GonzalesCore.CoreManagers;
using Kypris2.CoreElements;
using Kypris2.Utils;
using Jamila2.Tools;

public partial class GonzalesAdminAuthorizedListing : System.Web.UI.Page
{
    #region Variables

    protected PrivateLoginSession CurrentPrivateSession = null;
    protected LogManager CurLogManager = null;
    protected DataObj CurPageDataObj = new DataObj();

    #region EntityID
    protected string EntityID
    {
        get
        {
            return (ViewState["id"] != null) ? ViewState["id"].ToString() : null;
        }

        set
        {
            ViewState["id"] = value;
        }
    }
    #endregion

    #region ResultTable
    protected DataTable ResultTable
    {
        get
        {
            return (DataTable)ViewState["ResultTable"];
        }

        set
        {
            ViewState["ResultTable"] = value;
        }
    }
    #endregion

    #region GridViewHeader
    protected ArrayList GridViewHeader
    {
        get
        {
            return (ArrayList)ViewState["GridViewHeader"];
        }

        set
        {
            ViewState["GridViewHeader"] = value;
        }
    }
    #endregion

    #region DuplicateAuthorizerMessage
    protected string DuplicateAuthorizerMessage
    {
        get
        {
            return ViewState["DuplicateAuthorizerMessage"].ToString();
        }

        set
        {
            ViewState["DuplicateAuthorizerMessage"] = value;
        }
    }
    #endregion

    #region EntityMessage
    protected string EntityMessage
    {
        get
        {
            return ViewState["EntityMessage"].ToString();
        }

        set
        {
            ViewState["EntityMessage"] = value;
        }
    }
    #endregion

    #region AuthorizerMessage
    protected string AuthorizerMessage
    {
        get
        {
            return ViewState["AuthorizerMessage"].ToString();
        }

        set
        {
            ViewState["AuthorizerMessage"] = value;
        }
    }
    #endregion

    #region LevelMessage
    protected string LevelMessage
    {
        get
        {
            return ViewState["LevelMessage"].ToString();
        }

        set
        {
            ViewState["LevelMessage"] = value;
        }
    }
    #endregion

    #region MinMaxMessage
    protected string MinMaxMessage
    {
        get
        {
            return ViewState["MinMaxMessage"].ToString();
        }

        set
        {
            ViewState["MinMaxMessage"] = value;
        }
    }
    #endregion

    #region MinMaxMessage2
    protected string MinMaxMessage2
    {
        get
        {
            return ViewState["MinMaxMessage2"].ToString();
        }

        set
        {
            ViewState["MinMaxMessage2"] = value;
        }
    }
    #endregion

    #region DUplicateLevelMessage
    protected string DUplicateLevelMessage
    {
        get
        {
            return ViewState["DUplicateLevelMessage"].ToString();
        }

        set
        {
            ViewState["DUplicateLevelMessage"] = value;
        }
    }
    #endregion

    #endregion

    #region Events

    #region Page_Load
    protected void Page_Load(object sender, EventArgs e)
    {
        this.SessionCheck();

        // every page load, need to clear the messagebox
        this.Table_MessageBox.Visible = false;

        // check if any data need to delete
        this.DeleteData();

        if (!IsPostBack)
        {
            if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinanceAdmin)
                if (!this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinancialManager)
                {
                    Button_Submit.Visible = false;
                }
            this.SwitchLanguage();
            this.PageComponentSetup();

            this.LoadData();

            if (this.ResultTable != null)
            {
                DataView ResultView = new DataView(this.ResultTable);
                ResultView.Sort = this.DropDownList_SortBy.SelectedValue + " " + this.DropDownList_SortOrder.SelectedValue;
                this.BindData(ResultView);
            }
        } 
    }
    #endregion

    #region DropDownList_ByEntity_SelectedIndexChanged
    protected void DropDownList_ByEntity_SelectedIndexChanged(object sender, EventArgs e)
    {

        this.LoadData();
        this.LabelValue_Entity.Text = this.DropDownList_ByEntity.SelectedItem.Text;

        if (this.ResultTable != null)
        {
            DataView ResultView = new DataView(this.ResultTable);
            ResultView.Sort = this.DropDownList_SortBy.SelectedValue + " " + this.DropDownList_SortOrder.SelectedValue;
            this.BindData(ResultView);
        }
    }
    #endregion

    #region DropDownList_SortBy_SelectedIndexChanged
    protected void DropDownList_SortBy_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    #endregion

    #region DropDownList_SortOrder_SelectedIndexChanged
    protected void DropDownList_SortOrder_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    #endregion

    #region Button_Submit_Click
    protected void Button_Submit_Click(object sender, EventArgs e)
    {
        try
        {
            if (this.DataValidate())
            {
                using (UserManager CurUserManager = new UserManager(this.CurrentPrivateSession))
                {
                    if (CurUserManager.AddNewAuthorizer(
                        this.DropDownList_ByEntity.SelectedValue,
                        this.HiddenField_PersonnelInternalID.Value,
                        Int32.Parse(this.TextBox_Level.Text),
                        new Currency(this.DropDownList_Currency.SelectedValue, this.DropDownList_Currency.SelectedValue),
                        decimal.Parse(this.TextBox_Min.Text),
                        decimal.Parse(this.TextBox_Max.Text)))
                    {
                        //FRANK jan-2013
                        // log down the history
                        //this.CurLogManager.LogMessage("[GonzalesAdminAuthorizedListing] : New Authorizer (" + this.DropDownList_ByEntity.SelectedValue + ", " + this.HiddenField_PersonnelInternalID.Value + ", Level " + this.TextBox_Level.Text + ", " + this.DropDownList_Currency.SelectedValue + " " + this.TextBox_Min.Text + " - " + this.TextBox_Max.Text + ") added", this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);
                        this.CurLogManager.LogMessageFull("[GonzalesAdminAuthorizedListing] : New Authorizer (" + this.DropDownList_ByEntity.SelectedValue + ", " + this.HiddenField_PersonnelInternalID.Value + ", Level " + this.TextBox_Level.Text + ", " + this.DropDownList_Currency.SelectedValue + " " + this.TextBox_Min.Text + " - " + this.TextBox_Max.Text + ") added", this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User
                            , this.HiddenField_PersonnelInternalID.Value,
                            "", "Authorizer", "Add", "", "", "", "", "", "", "", "", "", "", "",
                            Convert.ToDouble(this.TextBox_Min.Text), Convert.ToDouble(this.TextBox_Max.Text), "GonzalesAdminAuthorizedListing", this.TextBox_Level.Text);

                        // refresh the data
                        this.LoadData();

                        if (this.ResultTable != null)
                        {
                            DataView ResultView = new DataView(this.ResultTable);
                            ResultView.Sort = this.DropDownList_SortBy.SelectedValue + " " + this.DropDownList_SortOrder.SelectedValue;
                            this.BindData(ResultView);
                        }

                        // clean up the form
                        this.TextBox_Level.Text = this.TextBox_Max.Text = this.TextBox_Min.Text = "0";
                        this.HiddenField_PersonnelInternalID.Value = "";                                       
                    }
                    else
                    {
                        this.CurLogManager.LogError("[GonzalesAdminAuthorizedListing.Button_Submit_Click] : Failed at CurUserManager.AddNewAuthorizer() : " + CurUserManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                        this.ShowErrorMessage(CurUserManager.ErrorMessage);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            this.ShowErrorMessage(ex.Message);
        }
    }
    #endregion

    #region OnRowCreated
    protected void OnRowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            TableCellCollection cells = e.Row.Cells;

            for (int i = 0; i < this.GridViewHeader.Count; i++)
            {
                cells[i].Text = this.GridViewHeader[i].ToString();
            }
        }
    }
    #endregion

    #endregion

    #region Customized Methods

    #region SessionCheck
    public void SessionCheck()
    {

        if (Session[GonzalesCommonNamingConvention.CurrentPrivateSession] != null)
        {
            this.CurrentPrivateSession = (PrivateLoginSession)Session[GonzalesCommonNamingConvention.CurrentPrivateSession];
            this.CurLogManager = new LogManager(this.CurrentPrivateSession);    // activate Log Manager
        }
        else
        {
            Response.Redirect(GonzalesErrorPageRedirect.SessionError);
        }

    }
    #endregion

    #region PageComponentSetup
    protected void PageComponentSetup()
    {
        // setup entity
        if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsPowerAdmin)
        {
            #region Power Admin
            using (EntityManager CurEntityManager = new EntityManager(this.CurrentPrivateSession))
            {
                MasterBaseCollection ResultList = CurEntityManager.GetAllEntity();
                if (ResultList != null)
                {
                    this.DropDownList_ByEntity.Items.Add(new ListItem("", ""));
                    for (int x = 0; x < ResultList.Count; x++)
                    {
                        this.DropDownList_ByEntity.Items.Add(new ListItem(ResultList[x].DisplayName, ResultList[x].InternalID));
                    }
                }
                else
                {
                    // display error
                    this.CurLogManager.LogError("[GonzalesAdminClaimantsListing.PageComponentSetup] : Failed on CurEntityManager.GetAllEntity() : " + CurEntityManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);

                }
            }
            #endregion
        }
        else
        {
            #region Finance Admin

            using (UserManager CurManager = new UserManager(this.CurrentPrivateSession))
            {
                MasterBaseCollection ResultList = CurManager.GetEntityByFinanceAdmin(this.CurrentPrivateSession.CurrentLoggedOnUser.InternalID);
                if (ResultList != null)
                {
                    for (int x = 0; x < ResultList.Count; x++)
                    {
                        this.DropDownList_ByEntity.Items.Add(new ListItem(ResultList[x].DisplayName, ResultList[x].InternalID));
                    }
                }
                else
                {
                    // display error
                    this.CurLogManager.LogError("[GonzalesAdminClaimantsListing.PageComponentSetup] : Failed on CurEntityManager.GetAllEntity() : " + CurManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }

            #endregion
        }

        if (Request.QueryString["entity"] != null)
        {
            this.DropDownList_ByEntity.SelectedItem.Selected = false;
            this.DropDownList_ByEntity.Items.FindByValue(Request.QueryString["entity"]).Selected = true;

            this.DropDownList_ByEntity_SelectedIndexChanged(null, null);

            
        }
        else
        {

            this.DropDownList_ByEntity_SelectedIndexChanged(null, null);
        }

        // setup currency
        using (CurrencyManager CurCurrencyManager = new CurrencyManager(this.CurrentPrivateSession))
        {
            MasterBaseCollection ResultList = CurCurrencyManager.GetAllCurrency();
            if (ResultList != null)
            {
                for (int x = 0; x < ResultList.Count; x++)
                {
                    this.DropDownList_Currency.Items.Add(new ListItem(ResultList[x].DisplayName, ResultList[x].InternalID));
                }

                this.DropDownList_Currency.Items.FindByText("USD").Selected = true;
            }
            else
            {
                // display error

                this.CurLogManager.LogError("[GonzalesAdminAuthorizedListing.PageComponentSetup] : Failed on CurCurrencyManager.GetAllEntity() : " + CurCurrencyManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);

            }
        }

        this.Button_Browse.Attributes["onclick"] = "ShowModal('AddressBook', document.getElementById('ModalResult')); return false;";

    }
    #endregion

    #region SwitchLanguage
    protected void SwitchLanguage()
    {
        try
        {
            using (MultiLingualFactory CurLanguageFactory = MultiLingualEngine.GetMultiLingualFactory(this, this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedLanguage.InternalID))
            {
                this.Label_AddNew.Text = CurLanguageFactory.DisplayValue("AddNew");
                this.Label_AuthorizedLimit.Text = CurLanguageFactory.DisplayValue("AuthorizedLimit");
                this.Label_AuthorizedLimit2.Text = CurLanguageFactory.DisplayValue("AuthorizedLimit2");
                this.Label_Entity.Text = CurLanguageFactory.DisplayValue("Entity");
                this.Label_Information.Text = CurLanguageFactory.DisplayValue("Information");
                this.Label_PageTitle.Text = CurLanguageFactory.DisplayValue("PageTitle");
                this.Label_Personnel.Text = CurLanguageFactory.DisplayValue("Personnel");
                this.Label_To.Text = CurLanguageFactory.DisplayValue("To");
                this.Button_Browse.Text = CurLanguageFactory.DisplayValue("Browse");
                this.Button_Submit.Text = CurLanguageFactory.DisplayValue("Submit");

                this.GridViewHeader = new ArrayList();
                this.GridViewHeader.Add(CurLanguageFactory.DisplayValue("Level"));
                this.GridViewHeader.Add(CurLanguageFactory.DisplayValue("EmployeeID"));
                this.GridViewHeader.Add(CurLanguageFactory.DisplayValue("ADName"));
                this.GridViewHeader.Add(CurLanguageFactory.DisplayValue("Name"));
                this.GridViewHeader.Add(CurLanguageFactory.DisplayValue("ApprovingLimitInString"));

                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("Level"), this.CurPageDataObj.Level));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("EmployeeID"), this.CurPageDataObj.EmployeeID));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("Name"), this.CurPageDataObj.Name));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ApprovingLimitInString"), this.CurPageDataObj.ApprovingLimitInString));                

                this.DropDownList_SortOrder.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ASC"), "ASC"));
                this.DropDownList_SortOrder.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("DESC"), "DESC"));
            }
        }
        catch (Exception ex)
        {
            this.CurLogManager.LogError("[GonzalesAdminAuthorizedListing.SwitchLanguage.EX] : " + ex.Message, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);
        }

    }
    #endregion

    #region ShowErrorMessage
    
    protected void ShowErrorMessage(string ErrorMessage)
    {
        this.Table_MessageBox.Visible = true;
        this.Table_MessageBox.Rows[0].Cells[0].Text = ErrorMessage;
    }

    protected void ShowErrorMessage(ArrayList ErrorMessageList)
    {
        if (ErrorMessageList != null)
        {
            StringBuilder ErrorMessageBuilder = new StringBuilder("<ul>");

            for (int x = 0; x < ErrorMessageList.Count; x++)
            {
                ErrorMessageBuilder.AppendLine("<li>" + ErrorMessageList[x] + "</li>");
            }

            ErrorMessageBuilder.AppendLine("</ul>");

            this.Table_MessageBox.Visible = true;
            this.Table_MessageBox.Rows[0].Cells[0].Text = ErrorMessageBuilder.ToString() ;
        }
    }

    #endregion

    #endregion

    #region Data Operation

    #region LoadData
    protected void LoadData()
    {
        this.EntityID = (Request.QueryString["entity"] != null) ? Request.QueryString["entity"] : null;

        if (this.EntityID != null)
        {
            this.DropDownList_ByEntity.SelectedItem.Selected = false;
            this.DropDownList_ByEntity.Items.FindByValue(this.EntityID).Selected = true;
        }

        if (this.DropDownList_ByEntity.SelectedValue.Length > 0)
        {
            this.EntityID = this.DropDownList_ByEntity.SelectedValue;

            using (UserManager CurUserManager = new UserManager(this.CurrentPrivateSession))
            {
                SystemUsers ResultAuthorizers = CurUserManager.GetAuthorizersByEntity(this.EntityID);

                if (ResultAuthorizers != null)
                {
                    this.ResultTable = new DataTable();
                    this.ResultTable.Columns.Add (new DataColumn(this.CurPageDataObj.InternalID, Type.GetType("System.String")));
                    this.ResultTable.Columns.Add (new DataColumn(this.CurPageDataObj.EmployeeID, Type.GetType("System.String")));
                    this.ResultTable.Columns.Add (new DataColumn(this.CurPageDataObj.Name, Type.GetType("System.String")));
                    this.ResultTable.Columns.Add (new DataColumn(this.CurPageDataObj.Level, Type.GetType("System.Int32")));
                    this.ResultTable.Columns.Add (new DataColumn(this.CurPageDataObj.ADName, Type.GetType("System.String")));
                    this.ResultTable.Columns.Add (new DataColumn(this.CurPageDataObj.ApprovingLimitCurrency, Type.GetType("System.String")));
                    this.ResultTable.Columns.Add (new DataColumn(this.CurPageDataObj.ApprovingLimitMin, Type.GetType("System.Decimal")));
                    this.ResultTable.Columns.Add (new DataColumn(this.CurPageDataObj.ApprovingLimitMax, Type.GetType("System.Decimal")));
                    this.ResultTable.Columns.Add (new DataColumn(this.CurPageDataObj.ApprovingLimitInString, Type.GetType("System.String")));
                    this.ResultTable.Columns.Add (new DataColumn(this.CurPageDataObj.EditLink, Type.GetType("System.String")));
                    this.ResultTable.Columns.Add (new DataColumn(this.CurPageDataObj.DeleteLink, Type.GetType("System.String")));

                    for (int x = 0; x < ResultAuthorizers.Count; x++)
                    {                        
                        Authoriser CurAuthorizer = (Authoriser)ResultAuthorizers[x];

                        DataRow ResultRow = this.ResultTable.NewRow();

                        ResultRow[this.CurPageDataObj.InternalID] = CurAuthorizer.InternalID;
                        ResultRow[this.CurPageDataObj.EmployeeID] = CurAuthorizer.EmployeeID;
                        ResultRow[this.CurPageDataObj.ADName] = CurAuthorizer.EmailID; ;
                        ResultRow[this.CurPageDataObj.Name] = CurAuthorizer.DisplayName;
                        ResultRow[this.CurPageDataObj.Level] = CurAuthorizer.Level;
                        ResultRow[this.CurPageDataObj.ApprovingLimitCurrency] = CurAuthorizer.LimitCurrency.InternalID;
                        ResultRow[this.CurPageDataObj.ApprovingLimitMin] = CurAuthorizer.MinLimit;
                        ResultRow[this.CurPageDataObj.ApprovingLimitMax] = CurAuthorizer.MaxLimit;
                        ResultRow[this.CurPageDataObj.ApprovingLimitInString] = CurAuthorizer.LimitCurrency.InternalID + " " + CurAuthorizer.MinLimit.ToString(GonzalesGeneralVariables.CurrencyFormat) + " - " + CurAuthorizer.MaxLimit.ToString(GonzalesGeneralVariables.CurrencyFormat);
                        string deleteurl = "";
                        deleteurl = "<a href='GonzalesAdminAuthorizedListing.aspx?DELETE=TRUE&id=" + CurAuthorizer.InternalID
                            + "&entity=" + this.EntityID
                            + "&min=" + CurAuthorizer.MinLimit.ToString()
                            + "&max=" + CurAuthorizer.MaxLimit.ToString()
                            + "' onclick=\"return confirm('Are you sure?');\" class='GridViewLink'>Delete</a>";
                        if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinanceAdmin)
                        {
                            if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinancialManager)
                            {
                                ResultRow[this.CurPageDataObj.EditLink] = "<a href='GonzalesAdminAuthorizedDetail.aspx?uid=" + CurAuthorizer.InternalID + "&entity=" + this.EntityID + "'  class='GridViewLink'>Edit</a>";
                                ResultRow[this.CurPageDataObj.DeleteLink] = deleteurl;
                            }
                        }
                        else
                        {
                            ResultRow[this.CurPageDataObj.EditLink] = "<a href='GonzalesAdminAuthorizedDetail.aspx?uid=" + CurAuthorizer.InternalID + "&entity=" + this.EntityID + "'  class='GridViewLink'>Edit</a>";
                            ResultRow[this.CurPageDataObj.DeleteLink] = deleteurl;
                        }
                            this.ResultTable.Rows.Add(ResultRow);
                    }
                }
                else
                {
                    // log error, display error
                    this.CurLogManager.LogError("[GonzalesAdminAuthorizedListing.LoadData] : Failure in CurUserManager.GetAuthorizersByEntity('" + this.EntityID + "') : " + CurUserManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }
        }
        else
        {
            // redirect
        }
    }

    #endregion

    #region DataValidate
    protected bool DataValidate()
    {
        bool smooth = true;
        ArrayList ErrorMessageList = new ArrayList();

        // validate entity
        if (this.DropDownList_ByEntity.SelectedValue.Length == 0)
        {
            ErrorMessageList.Add(this.EntityMessage);
            smooth = false;
        }

        // validate employee
        if (this.LabelValue_Personnel.Text.Length < 0)
        {
            ErrorMessageList.Add(this.AuthorizerMessage);
            smooth = false;
        }

        // validate level
        int InputLevel = 0;
        if (this.TextBox_Level.Text.Trim().Length == 0 || !Int32.TryParse(this.TextBox_Level.Text, out InputLevel) || InputLevel < 0)
        {
            ErrorMessageList.Add(this.LevelMessage);
            smooth = false;
        }

        // validate min and max
        decimal MinAmount = 0, MaxAmount = 0;
        if (this.TextBox_Min.Text.Trim().Length == 0 || !decimal.TryParse(this.TextBox_Min.Text, out MinAmount) ||
            this.TextBox_Max.Text.Trim().Length == 0 || !decimal.TryParse(this.TextBox_Max.Text, out MaxAmount) || 
            MinAmount < 0 || MaxAmount < 0)
        {
            ErrorMessageList.Add(this.MinMaxMessage);
            smooth = false;
        }
        else
        {
            if (MinAmount > MaxAmount || MinAmount == MaxAmount)
            {
                ErrorMessageList.Add(this.MinMaxMessage2);
                smooth = false;
            }
        }

        // validate the level
        if (this.ResultTable != null && smooth)
        {            
            foreach (DataRow ResultRow in this.ResultTable.Rows)
            {
                int CurrentLevel = Convert.ToInt32(ResultRow[this.CurPageDataObj.Level]);
                string CurrentPersonnelInternalID = ResultRow[this.CurPageDataObj.InternalID].ToString();

                if (CurrentLevel == InputLevel)
                {
                    // there is a equal level! not valid
                    ErrorMessageList.Add(this.DUplicateLevelMessage);
                    smooth = false;
                }

                if (CurrentPersonnelInternalID.CompareTo(this.HiddenField_PersonnelInternalID.Value) == 0)
                {
                    // there is a same personnel! not valid
                    ErrorMessageList.Add(this.DuplicateAuthorizerMessage);
                    smooth = false;
                }
            }
        }

        if (!smooth) this.ShowErrorMessage(ErrorMessageList);

        return smooth;
    }
    #endregion

    #region DeleteData
    protected bool DeleteData()
    {
        bool smooth = true;

        if (Request.QueryString["DELETE"] != null && Request.QueryString["DELETE"] == "TRUE" &&
            Request.QueryString["id"] != null && Request.QueryString["id"].Length == 36 &&
            Request.QueryString["entity"] != null)
        {
            using (UserManager CurUserManager = new UserManager(this.CurrentPrivateSession))
            {
                smooth = CurUserManager.DeleteAuthorizer(Request.QueryString["entity"], Request.QueryString["id"]);

                if (smooth)
                {
                    // log down the history
                    //this.CurLogManager.LogMessage("[GonzalesAdminAuthorizedListing] : Authorizer (" + this.DropDownList_ByEntity.SelectedValue + ", " + Request.QueryString["id"] + ") deleted", this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);
                    //FRANK
                    this.CurLogManager.LogMessageFull("[GonzalesAdminAuthorizedListing] : Authorizer (" + this.DropDownList_ByEntity.SelectedValue + ", " + Request.QueryString["id"] + ") deleted", this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User
                       , Request.QueryString["id"],
                       "", "Authorizer", "Delete", "", "", "", "", "", "", "", "", "", "", "", double.Parse(Request.QueryString["min"]), double.Parse(Request.QueryString["max"]), "GonzalesAdminAuthorizedListing", "0");

                    this.EntityID = Request.QueryString["entity"];
                }
                else
                {
                    this.CurLogManager.LogError("[GonzalesAdminAuthorizedListing.DeleteData] : Failed at CurUserManager.DeleteAuthorizer('" + Request.QueryString["entity"] + "', '" + Request.QueryString["id"] + "') : " + CurUserManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                    this.ShowErrorMessage(CurUserManager.ErrorMessage);
                }
            }
        }

        return smooth;
    }
    #endregion

    private void BindData(DataView result)
    {
        this.GridViewResult.DataSource = result;
        this.GridViewResult.DataBind();
    }

    private void BindData(DataView result, int pageindex)
    {
        this.GridViewResult.PageIndex = pageindex;
        this.GridViewResult.DataSource = result;
        this.GridViewResult.DataBind();
    }

    #endregion

    #region Class: DataObj

    protected class DataObj
    {
        public readonly string InternalID = "InternalID";        
        public readonly string EmployeeID = "EmployeeID";
        public readonly string ADName = "ADName";
        public readonly string Name = "Name";
        public readonly string Level = "Level";
        public readonly string ApprovingLimitCurrency = "ApprovingLimitCurrency";
        public readonly string ApprovingLimitMin = "ApprovingLimitMin";
        public readonly string ApprovingLimitMax = "ApprovingLimitMax";
        public readonly string ApprovingLimitInString = "ApprovingLimitInString";
        public readonly string EditLink = "EditLink";
        public readonly string DeleteLink = "DeleteLink";

    }

    #endregion
}
